package minNumberOfHours;

public class Solution {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        // 先保证精力
        // 再保证经验
        // 5>1 -- +1 +3+2
        int neededEnergy = 0;
        for (int i = 0; i < energy.length; i++) {
            if(initialEnergy<=energy[i]) {
                neededEnergy+=(energy[i]+1 - initialEnergy);
                initialEnergy = 1;
            }else {
                initialEnergy-=energy[i];
            }
        }
        int neededExperince = 0;
        for (int i = 0; i < experience.length; i++) {
            if(initialExperience<=experience[i]) {
                // 经验不够 需要训练
                neededEnergy+=(experience[i]+1-initialEnergy);
            }
            initialExperience+=experience[i];
        }
        return neededEnergy+neededExperince;
    }
}
